import { messages } from "share/common";
import { Checkbox, message, Popover } from "antd";
import React from "react";

const typeCode = {
  PLANE_CABIN: messages("expense-8.key452") /*飞机舱等*/,
  TRAIN_SEAT_CLASS: messages("expense-8.key453") /*火车座等*/,
  SHIP_CABIN: messages("expense-8.key454") /*轮船座次*/,
};

let ruleColumns = (customEnumerationList, nonAmountCtrlItem) => {
  return [
    {
      dataIndex: "userGroups",
      title: messages("expense-8.key11") /*适用人员*/,
      width: "20%",
      render: (value, record) => {
        let showUser = (value || []).map((i) => i.name);
        let showValue =
          `${record.userAssociateType === 0 ? `(${messages("expense-8.key73") /*不包含*/})` : ""}` +
          showUser.join("、");
        return showUser.length ? (
          <Popover placement="topLeft" content={showValue}>
            {showValue}
          </Popover>
        ) : (
          messages("expense-8.key9")
        ); /*通用*/
      },
    },
    {
      dataIndex: "customEnumerationItems",
      title: typeCode[nonAmountCtrlItem],
      width: "40%",
      render: (value) => (
        <span style={{ whiteSpace: "pre-line" }}>
          {(value || [])
            .sort(
              (a, b) =>
                customEnumerationList.findIndex((i) => i.value === a.value) -
                customEnumerationList.findIndex((i) => i.value === b.value)
            )
            .map((i) => i.messageKey)
            .filter((i) => !!i)
            .join("，")}
        </span>
      ),
    },
  ];
};

export default ruleColumns;
